<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>view/workArea/tools/applyTools</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../../../css/mui.min.css">
		<link rel="stylesheet" href="../../../css/global.css">
		<link rel="stylesheet" href="../../../css/style.css">
		<link rel="stylesheet" href="../../../css/mui.picker.css">
		<link rel="stylesheet" href="../../../css/mui.poppicker.css">
		<style>
			 .mui-radio input[type=radio]{
				left: 0;
				top: 12px;
			}
			.mui-radio input[type=radio]:before{
				font-size: 18px;
			}
			.mui-radio.mui-left label{
				padding-left: 40px;
				line-height: 50px;
			}
			.mui-checkbox, .mui-radio{
				float: left;
			}
		</style>
		<style>
			.mui-btn {
				font-size: 16px;
				padding: 8px;
				margin: 3px;
			}
			h5.mui-content-padded {
				margin-left: 3px;
				margin-top: 20px !important;
			}
			h5.mui-content-padded:first-child {
				margin-top: 12px !important;
			}
			.ui-alert {
				text-align: center;
				padding: 20px 10px;
				font-size: 16px;
			}
			.mui-btn-select{
				line-height: 3.125rem;
			}
			.sel{
				font-size: 12px;
				margin-left: 10px;
				color: #ffffff;
				background: #ea1e1a;
				height: 20px;
				line-height: 12px !important;
				margin-top: 14px;
				border-radius: 5px;
				padding: 5px;
			}
			.selectxx{
				position: absolute;
				right: 5px;
			}
			.details_con {
				margin: 20px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">工具借用</h1>
		</header>
		<div class="mui-content">
			<div class="details_con" id="form_info">
				<!--<div class="clum">
					<span class="name">编号</span>
					<input type="text" class="d_ipt" id="no" placeholder="请输入编号" />
				</div>
				<div class="clum">
					<span class="name">姓名</span>
					<input type="text" class="d_ipt" id="name" placeholder="请输入姓名" />
				</div>-->
				<div class="clum">
					<span class="name">发货联系人<em class="t_red">*</em></span>
					<input type="text" class="d_ipt" id="contactor" name="contactor" required="required" placeholder="请输入发货联系人" />
				</div>
				<div class="clum">
					<span class="name">联系电话<em class="t_red">*</em></span>
					<input type="text" class="d_ipt" id="mobile" name="mobile" required="required" placeholder="请输入联系电话" />
				</div>
				<!-- <div class="clum">
					<span class="name">所在地区<em class="t_red">*</em></span>
					<input type="text" class="d_ipt" id="address" name="address" required="required" placeholder="请输入所在地区" />
				</div> -->
				<div class="clum">
					<span class="name">所在地区<em class="t_red">*</em></span>
					<input type="hidden" id="Province" required="required" placeholder="请选择所在地区"/>
					<span class="txt">
						<button style="color: #a4a4a4;" id='showCityPicker3' class="mui-btn-select" type='button'>请选择所在地区</button>
					</span>
				</div>
				<div class="clum">
					<span class="name">详细地址<em class="t_red">*</em></span>
					<input type="text" id="shipaddress" name="shipaddress" required="required" class="d_ipt" placeholder="请输入详细地址" />
				</div>
				<div class="clum">
					<span class="name">期望到货日期<em class="t_red">*</em></span>
					<button type="button" class="selectDate" id='dateTimeBtn'>请选择日期</button>
					<input type="text" class="d_ipt" id="expectdate" name="expectdate" required="required" placeholder="请输入期望到货日期" />
				</div>
				<div class="clum">
					<span class="name">本次借用仪器台数</span>
					<input type="number" value="1" class="d_ipt" id="instrumentqty" name="instrumentqty" placeholder="请输入本次借用仪器台数" />
				</div>
			</div>
			<div class="btn_box">
				<span class="fl" id="cancelBtn">返回</span>
				<span class="fr red" id="submitBtn">提交</span>
			</div>
			<div style="height: 50px;"></div>
		</div>

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/utils/h.js"></script>
		<script src="../../../js/constant.js"></script>
		<script src="../../../js/common.js"></script>
		<script src="../../../js/utils/base64.js"></script>
		<script src="../../../js/utils/md5.js"></script>
		<script src="../../../js/utils/sortMap.js"></script>
		<script src="../../../js/utils/http.js"></script>
		<script src="../../../js/app.js"></script>
		<script src="../../../js/utils/rolldate.min.js"></script>
		<script src="../../../js/mui.picker.js"></script>
		<script src="../../../js/mui.poppicker.js"></script>
		<script src="../../../js/city.data-3.js" type="text/javascript" charset="utf-8"></script>
		<!-- 基础js end -->

		<script type="text/javascript" charset="utf-8">
			var applyPartsKey = "FSE_ITEM_KEY_APPLY_PARTS";
			(function($, doc) {
				$.init();
				
				new Rolldate({
					el: '#dateTimeBtn',
					format: 'YYYY-MM-DD',
					beginYear: 2015,
					endYear: 2050,
					trigger: 'click',
					lang: {
						title: '请选择期望到货日期',
					},
					confirm: function(date) {
						h("#expectdate").val(date);
					}
				})
				
				$.plusReady(function() {
					expectdateInit(); //自动带出当前日期+3天，可修改
					h("#contactor").val(emptyStr(app.getUser().name))
					h("#mobile").val(emptyStr(app.getUser().mobile))

					// 从上一个页面取值
					var self = plus.webview.currentWebview();
					var tools = self.tools;
					var toolIds = self.toolIds;
					
					// 页面自动带入值
					/*h("#no").val(toolIds);
					h("#name").val(app.getUser().name);*/
					
					// 收货地址二级联动
					var _getParam = function(obj, param) {
						return obj[param] || '';
					};
					h('#showCityPicker3').tap(function() {
						var cityPicker3 = new $.PopPicker({
							// layer: 3
							layer: 3 // 设为2级联动
						});
						// cityPicker3.setData(addressData);
						cityPicker3.setData(cityData3);
						cityPicker3.show(function(items) {
							h("#showCityPicker3").html( _getParam(items[0], 'text') + " " + _getParam(items[1], 'text') + " " + _getParam(items[2], 'text'));
							h("#Province").val(_getParam(items[0], 'value'));
						});
					});
					
					

					// 提交
					h('#submitBtn').tap(function() {
						var formObj = {}; //POST参数对象
						var subFlag = true; //可否提交标识
						// 表单内容获取
						mui("#form_info input, #form_info textarea").each(function(index, item) {
							var value = item.value;
							var name = item.getAttribute("id");
							// 校验必填
							var required = item.getAttribute("required");
							if (required && !value) {
								subFlag = false;
								app.toast(item.getAttribute("placeholder"));
								return false;
							}
							if (name == "Province") {
								return true;
							}
							if (name == "shipaddress") {
								var str = h("#showCityPicker3").html();
								formObj["address"] = h("#showCityPicker3").html() + " " + value;
								return true;
							}
							// 参数赋值
							formObj[name] = value;
						});
						
						// 提交校验
						if (subFlag) {
							// mobile 格式校验
							var mobile = h("#mobile").val();
							if(!/^[1][3,4,5,7,8][0-9]{9}$/.test(mobile)){
								app.toast("请输入有效联系电话");
								return false;
							}
							formObj["enginner_id"] = app.getUser().enginnerId;
							var postParam = {
								"applyMain" : JSON.stringify(formObj),
								"applyTools" :  tools
							}
							// 提交数据
							app.showWaiting('加载中...')
							ajaxPost(BASE_URL + "cc/tool/applyBorrowTool", postParam, function(data) {
								app.closeWaiting()
								// console.log(JSON.stringify(data));
								if (data.code == 200) {//查询成功
									app.toast("保存成功");
									
									// 返回上一页并刷新
									var priorPage = plus.webview.getWebviewById('view/workArea/tools/borrowTools');
									priorPage.evalJS('selectList()')
									$.back()
								} else {//查询失败
									app.toast("保存失败");
								}
							}, function(errorMsg) {
								app.closeWaiting()
								console.log(JSON.stringify(errorMsg))
							});
						}
					});
					
					// 返回
					h('#cancelBtn').tap(function() {
						app.back();
					});
				});
			}(mui, document));
			
			function expectdateInit() {
				var now = new Date().valueOf();
				var date = now + 3 * 24 * 60 * 60 * 1000
				var expectdate = new Date(date);
				h("#dateTimeBtn").html(expectdate.Format("yyyy-MM-dd"));
				h("#expectdate").val(expectdate.Format("yyyy-MM-dd"));
			}
		</script>
		<!-- js代码 end -->

	</body>

</html>
